package io.renren.modules.wcs.controller;

import com.ioserver.bean.Union_DataType;
import io.renren.common.utils.R;
import io.renren.modules.ioserver.IOServer;
import io.renren.modules.ioserver.IOServerService;
import io.renren.modules.wcs.entity.DDJJobEntity;
import io.renren.modules.wcs.service.DDJService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 蔡翔
 * @Date: 2019/11/7 8:59
 * @Version 1.0
 */
@RestController
@Api(description = "wmsTest接口")
@RequestMapping("/wmcTestTest")
@DependsOn("springContextUtils")
public class TestControllerSS {
    @Autowired
    DDJService ddjService;

    /**
     * caixiang
     * <p>
     * 返回值:
     * -1 代表 IOServer 写入异常
     * -2 代表 堆垛机在执行任务途中 出现故障。
     * 1 代表 堆垛机执行成功
     * 2 代表 重置任务失败。
     * 3 代表 分发任务失败
     **/
    @ApiOperation(value = "sendTaskAndListening", notes = "sendTaskAndListening")
    @PostMapping("/sendTaskAndListening")
    public R sendTaskAndListening(@RequestBody DDJJobEntity ddjJobEntity) throws Exception {
        //System.out.println("（开始）发起任务的线程是："+Thread.currentThread().getName());
        //System.out.println(ddjService.getClass()+":"+ddjService.hashCode());
        System.out.println(ddjService.getClass().toString()+"  "+ddjService.hashCode());
        Integer integer = ddjService.sendTaskAndListening(ddjJobEntity);
        //System.out.println("（结束）发起任务的线程是："+Thread.currentThread().getName());
        return R.ok().put("result",integer);
    }

    @ApiOperation(value = "testEnum", notes = "testEnum")
    @PostMapping("/testEnum")
    public R testEnum(String name) throws Exception {
        final IOServerService instance = IOServer.INSTANCE.getInstance();
        final Union_DataType.ByValue valueByName = instance.getValueByName(name);
        return R.ok().put("result",valueByName);
    }
}
